﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PubSubLite.Configuration;
using PubSubLite.Messaging;
using PubSubLite.Messaging.MessageChannels;

namespace PubSubLite.IOC
{
    /// <summary>
    /// Contains all type mappings needed to register PubSubLite
    /// in an IOC container.
    /// </summary>
    public class PubSubLiteMappingsModule : TypeMappingsModule
    {
        /// <summary>
        /// Mapping name constants
        /// </summary>
        public static class MappingNames
        {
            /// <summary>
            /// Mapping name for IBus
            /// </summary>
            public const string Bus = "PubSubLite.Bus";
            /// <summary>
            /// Mapping name for IBusConfiguration
            /// </summary>
            public const string BusConfiguration = "PubSubLite.BusConfiguration";
            /// <summary>
            /// Mapping name for ISubscriberStorage
            /// </summary>
            public const string SubscribersStorage = "PubSubLite.SubscribersStorage";
            public const string MessageChannel = "PubSubLite.MessageChannel";
            public const string CommandDispatcher = "PubSubLite.CommandDispatcher";
            public const string MessageDispatcher = "PubSubLite.MessageDispatcher";
            public const string MessageChannelListener = "PubSubLite.MessageChannelListener";
            public const string MessageRouter = "PubSubLite.MessageRouter";
            public const string MessageChannelProvider = "PubSubLite.MessageChannelProvider";
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        public PubSubLiteMappingsModule()
            : base()
        {
            RegisterMapping<IBus, Bus>(MappingNames.Bus);
            RegisterMapping<IBusConfiguration, BusConfiguration>(MappingNames.BusConfiguration);
            RegisterMapping<ISubscribersStorage, SubscribersStorage>(MappingNames.SubscribersStorage);

            // Messaging
            RegisterMapping<IMessageChannel, InMemoryMessageChannel>(MappingNames.MessageChannel);
            RegisterMapping<ICommandDispatcher, CommandDispatcher>(MappingNames.CommandDispatcher);
            RegisterMapping<IMessageDispatcher, MessageDispatcher>(MappingNames.MessageDispatcher);
            RegisterMapping<IMessageChannelListener, MessageChannelListener>(MappingNames.MessageChannelListener);
            RegisterMapping<IMessageRouter, MessageRouter>(MappingNames.MessageRouter);
            RegisterMapping<IMessageChannelProvider, MessageChannelProvider>(MappingNames.MessageChannelProvider);
        }
    }
}
